﻿using Architecture.Api.Application.Command.UserCommand;
using Architecture.Domain.RBAC;
using Architecture.Service;
using MediatR;

namespace Architecture.Api.Application.CommandHandlers.UserHandler
{
    public class UserCreateCommandHandler : IRequestHandler<UserCreateCommand, int>
    {
        private readonly IUserService _userService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userService"></param>
        public UserCreateCommandHandler(IUserService userService)
        {
            _userService = userService;
        }

        public async Task<int> Handle(UserCreateCommand request, CancellationToken cancellationToken)
        {
            return await _userService.AddAsync(new UserInfo() {
                UserName=request.UserName,
                UserSex=request.UserSex,
                UserAddress=request.UserAddress,
                ProvinceId=request.ProvinceId,
                UrbanId=request.UrbanId,
                CountyId=request.CountyId 
            });
        }
    }
}
